package com.icehand.demo.service.strategy;

import com.icehand.demo.enums.ResultCodeEnums;
import com.icehand.demo.exception.BizException;
import com.icehand.demo.utils.SpringContextUtils;
import lombok.AllArgsConstructor;

import java.util.Map;

@AllArgsConstructor
public class OrderHandlerContext {
    private Map<Integer, Class> orderHandlerMap;

    public AbstractOrderHandler getInstance(int type){
        Class clazz = orderHandlerMap.get(type);
        if(null == clazz) {
            throw new BizException(ResultCodeEnums.NOT_SUPPORT);
        }

        return (AbstractOrderHandler) SpringContextUtils.getBean(clazz);
    }
}
